{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}

<div class="label-capacity-container">
  <div class="panel panel-default">
    <div class="panel-heading">
      <div id="collapseLabelCapacityPanelBtn" href="#collapsibleLabelCapacityPanel" data-toggle="collapse" {{bind-attr class=":panel-title :collapsible-panel-btn view.isLabelsPanelCollapsed:collapsed"}}>
        Label Capacity
        {{#if isAnyChildrenQueueLabelDirty}}
          {{#if warnInvalidTotalLabelCapacity}}
            {{warning-info class="red" tooltip="Invalid label total capacity"}}
          {{else}}
            {{warning-info class="yellow-warning" tooltip="Need refresh queues / restart RM"}}
          {{/if}}
        {{/if}}
        <a class="pull-right"><i {{bind-attr class=":fa view.isLabelsPanelCollapsed:fa-plus:fa-minus"}}></i></a>
      </div>
    </div>
    <div id="collapsibleLabelCapacityPanel" {{bind-attr class=":panel-collapse :collapse view.isLabelsPanelCollapsed::in"}}>
      <div class="panel-body">
        {{#if isOperator}}
          {{#if isNodeLabelsEnabledAndConfiguredByRM}}
            <div class="label-names">
              <label>Accessible Node Labels: </label>
              <span>{{accessibleLabelNames}}</span>
            </div>
            <div class="row">
              <div class="col-sm-6 col-md-6">
                <label>Default Label: </label>
                <span>{{selectedDefaultNodeLabel}}</span>
                {{#if isDefaultNodeLabelInherited}}
                  {{#unless isRoot}}
                    {{#if isValidDefaultNodeLabel}}
                      <span>(Inherited)</span>
                    {{/if}}
                  {{/unless}}
                {{/if}}
              </div>
              <div class="col-sm-6 col-md-6">
                <label>Set Default Node Label: </label>
                {{view Ember.Select
                  class="default-label-options"
                  content=defaultNodeLabelOptions
                  optionLabelPath="content.label"
                  optionValuePath="content.value"
                  value=queueDefaultNodeLabelExpression
                }}
                {{#if queueDirtyFields.default_node_label_expression}}
                  <div class="btn-group btn-group-xs">
                    <a {{action 'rollbackProp' 'default_node_label_expression' content}} href="#" class="btn btn-default btn-warning"><i class="fa fa-undo"></i></a>
                  </div>
                {{/if}}
              </div>
            </div>
            {{#if isRoot}}
              <div class="border-wrapper">
                <div class="row">
                  <div class="col-sm-2 col-md-2">
                    <label>Label</label>
                  </div>
                  <div class="col-sm-3 col-md-3">
                    <label>Label Capacity</label>
                  </div>
                  <div class="col-sm-3 col-md-3">
                    <label>Label Max Capacity</label>
                  </div>
                </div>
                {{#if hasAnyNodeLabelsForQueue}}
                  {{#each label in sortedAllLabelsForQueue}}
                    {{display-root-label queueLabels=queueNodeLabels nonAccessibleLabels=nonAccessibleLabels label=label isRoot=isRoot}}
                  {{/each}}
                {{else}}
                  <div class="row">
                    <div class="col-md-12 col-sm-12">
                      <small>No Node Labels Defined</small>
                    </div>
                  </div>
                {{/if}}
              </div>
            {{/if}}
            {{#if isLeafQ}}
              {{#if hasQueueLabels}}
                {{#each label in queueNodeLabels}}
                  {{display-leaf-label label=label}}
                {{/each}}
              {{else}}
                <div class="">
                  <small>Node labels are not enabled. Goto parent queue to enable them.</small>
                </div>
              {{/if}}
            {{else}}
              {{#if hasChildrenQueueLabels}}
                {{#each childQLabel in childrenQueueLabels}}
                  <div class="border-wrapper">
                    <div class="">
                      <label>Label: </label>
                      <span>{{childQLabel.labelName}}</span>
                    </div>
                    <div class="row">
                      <div class="col-md-2 col-sm-2">
                        <label>Children</label>
                      </div>
                      <div class="col-sm-4 col-md-4">
                        <label>Label Capacity</label>
                      </div>
                      <div class="col-sm-4 col-md-4">
                        <label>Label Max Capacity</label>
                      </div>
                    </div>
                    {{#each row in childQLabel.childrenQueueLabels}}
                      {{edit-label-capacity label=row.label queue=row.queue parentQueue=row.parentQueue}}
                    {{/each}}

                    {{label-capacity-bar queueLabels=childQLabel.childrenQueueLabels warnInvalidTotalLabelCapacity=warnInvalidTotalLabelCapacity}}
                  </div>
                {{/each}}
              {{else}}
                <div class="">
                  <small>Node labels are not enabled. Goto parent queue to enable them.</small>
                </div>
              {{/if}}
            {{/if}}
          {{else}}
            <div class="text-warning">
              {{#if isRmOffline}}
                <small>Unable to obtain information about the node labels from the resource manager</small>
              {{else}}
                {{#unless isNodeLabelsConfiguredByRM}}
                  <small>Node labels are not configured by resource manager</small>
                {{else}}
                  <small>Node labels are disabled by resource manager. Enable node labels to map the labels to queues.</small>
                {{/unless}}
              {{/if}}
            </div>
          {{/if}}
        {{else}}
          {{#if isNodeLabelsEnabledAndConfiguredByRM}}
            <div class="label-names">
              <label>Accessible Node Labels: </label>
              <span>{{accessibleLabelNames}}</span>
            </div>
            {{#if hasQueueLabels}}
              {{#each label in queueNodeLabels}}
                {{display-leaf-label label=label}}
              {{/each}}
            {{else}}
              <div class="">
                <small>Node labels are not enabled for this queue</small>
              </div>
            {{/if}}
          {{else}}
            <div class="text-warning">
              {{#if isRmOffline}}
                <small>Unable to obtain information about the node labels from the resource manager</small>
              {{else}}
                {{#unless isNodeLabelsConfiguredByRM}}
                  <small>Node labels are not configured by resource manager</small>
                {{else}}
                  <small>Node labels are disabled by resource manager</small>
                {{/unless}}
              {{/if}}
            </div>
          {{/if}}
        {{/if}}
      </div>
    </div>
  </div>
</div>
